import java.util.Scanner;
import java.util.Stack;

public class Question4 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int times = Integer.parseInt(scanner.nextLine());
        String[] operations = new String[times];
        MyQueue myQueue = new MyQueue();
        for (int i = 0; i < times ;i ++){
            operations[i] = scanner.nextLine();
        }
        for (int i = 0;i < times ; i ++){
            if (operations[i].startsWith("add")){
                String[] strings = operations[i].split(" ");
                int value = Integer.parseInt(strings[1]);
                myQueue.myAdd(value);
            }
            if (operations[i].startsWith("poll")){
                myQueue.myPoll();
            }
            if (operations[i].startsWith("peek")){
                System.out.println(myQueue.myPeek());
            }
        }
    }


}
class MyQueue{

    private Stack<Integer> stackHead=new Stack<>();
    private Stack<Integer> stackTail=new Stack<>();

    public void myAdd(int num){
        stackTail.push(num);
    }
    public int myPeek(){
        if (!stackHead.empty()){
            return stackHead.pop();
        }else {
            if (!stackTail.empty()){
                while (!stackTail.empty()){
                    stackHead.push(stackTail.pop());
                }
            }else {
                return -1;
            }
        }
        return stackHead.peek();
    }
    public int myPoll(){
        if (!stackHead.empty()){
            return stackHead.pop();
        }else {
            if (!stackTail.empty()){
                while (!stackTail.empty()){
                    stackHead.push(stackTail.pop());
                }
            }else {
                return -1;
            }
        }
        return stackHead.pop();
    }
}
